package com.jenkins.test.proxy.scan;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @version V0.0.1
 * @ClassName: {@link AutoDaoScanBeanDefinitionRegistrar}
 * @Description: AutoDaoScanBeanDefinitionRegistrar
 * @author: Lanzhou
 * @date: 2022/1/23 16:00
 * @Copyright:2019 All rights reserved.
 * 注意：本内容仅限于本人开发与维护，禁止外泄以及用于其他的商业目
 */
public class AutoDaoScanBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        // 获取MapperScan注解属性信息
        AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(MyDaoScan.class.getName()));
        // 获取注解的属性值,拿到定义的扫描路径
        assert annotationAttributes != null;
        String[] basePackages = annotationAttributes.getStringArray("basePackage");
        // 使用自定义扫描器扫描
        DaoScanClassPathBeanDefinitionScanner scanner = new DaoScanClassPathBeanDefinitionScanner(registry);
        scanner.scan(basePackages);
    }

}
